<?php
session_start();

include_once( 'lib/config.php' );
include_once( 'lib/oauth_lib.php' );
include_once( 'lib/weibooauth.php' );

$o = new WeiboOAuth( WB_AKEY , WB_SKEY  );
$keys = $o->getRequestToken();

$scheme = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on") ? 'http' : 'https';
$port = $_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443 ? ':'.$_SERVER['SERVER_PORT'] : '';
$oauth_callback = $scheme . '://' . $_SERVER['HTTP_HOST'] . $port . substr($_SERVER['PHP_SELF'],0,-9).'callback.php';

$aurl = $o->getAuthorizeURL( $keys['oauth_token'] ,false , $oauth_callback );

$_SESSION['keys'] = $keys;

$update_time = is_file(UPDATE_FILE) ? file_get_contents(UPDATE_FILE) : '无';
$weibo_oauthed = is_file(WB_OAUTH) ? '已登录，正在同步'.WB_USER.'的微博。<a href="logout.php?profile=weibo">注销</a>' : '未登录';
$twitter_oauthed = is_file(TW_OAUTH) ? '已登录。<a href="logout.php?profile=twitter">注销</a>' : '未登录';
?>
<p><a href="<?=$aurl?>">OAuth登录:新浪微博</a>(当前状态：<?php echo $weibo_oauthed?>)</p>
<p><a href="oauth.php">OAuth登录:Twitter</a>(当前状态：<?php echo $twitter_oauthed?>)</p>
<p>最后同步时间：<?php echo $update_time;?></p>
<p><a href="sync.php">手动同步</a></p>